﻿using System;
using System.Collections;
using System.Collections.Generic;
using ProtoBuf;
using GeneralDFS.Common;

namespace GeneralDFS.DataEntity.IO
{
    [ProtoContract]
    [Serializable]
    public class DirectoryNodeInfo : NodeBase
    {
        public List<NodeBase> Childs { set; get; }
        private const int ParamCapacity = 5;

        public DirectoryNodeInfo()
        {
            base.CreateTime = DateTime.Now.LongNow();
            base.CreaterName = "DefaultCreater";
            Init();
        }

        public DirectoryNodeInfo(String directoryName, String path, long createTime, String createrName, DirectoryNodeInfo parent)
        {
            base.Name=directoryName;
            base.FullPath = path;
            base.CreateTime = createTime;
            base.CreaterName=createrName;
            base.Parent = parent;
            Init();
        }

        /// <summary>
        /// 获取当前目录下所有的文件和文件夹
        /// </summary>
        /// <returns></returns>
        public List<NodeBase> GetAllChilds()
        {
            return Childs;
        }

        public void Init()
        {
            if(null!=Childs) throw new Exception("Child is not null,can not init the dir again!");
            Childs = new List<NodeBase>(ParamCapacity);
        }

        public Boolean IsRoot
        {
            get { return base.Name.Length == 0; }
        }

        public override bool IsDirectory()
        {
            return true;
        }

        public override void WriteToBinary(System.IO.BinaryWriter binaryWriter)
        {
            base.WriteToBinary(binaryWriter);
        }

        public override NodeBase ReadFromBinary(System.IO.BinaryReader binaryReader)
        {
            return base.ReadFromBinary(binaryReader);
        }
    }
}